package 数据结构.并查集;

import org.junit.Test;

import java.util.Random;

/**
 * @author Veng Su 1344114844@qq.com
 * @date 2018/8/5 19:14
 */
public class Main {
    @Test
    public void test(){
        int size =100000000;
        int m=100000000;
//        UnionFind1 unionFind1=new UnionFind1(size);
//        System.out.println("uf1 "+testUF(unionFind1,m)+" s");
//        UnionFind2 unionFind2=new UnionFind2(size);
//        System.out.println("uf2 "+testUF(unionFind2,m)+" s");
//        UnionFind3 unionFind3=new UnionFind3(size);
//        System.out.println("uf3 "+testUF(unionFind3,m)+" s");
//        UnionFind4 unionFind4=new UnionFind4(size);
//        System.out.println("uf4 "+testUF(unionFind4,m)+" s");
//        UnionFind5 unionFind5=new UnionFind5(size);
//        System.out.println("uf5 "+testUF(unionFind5,m)+" s");
        UnionFind6 unionFind6=new UnionFind6(size);
        System.out.println("uf6 "+testUF(unionFind6,m)+" s");
    }
    public double testUF(UnionFind unionFind,int m){
        int size=unionFind.getSize();
        Random random=new Random();
        long startTime =System.nanoTime();
        for (int i = 0; i < m; i++) {
            int a=random.nextInt(size);
            int b=random.nextInt(size);
            unionFind.unionElement(a,b);
        }
        for (int i = 0; i < m; i++) {
            int a=random.nextInt(size);
            int b=random.nextInt(size);
            unionFind.isConnected(a,b);
        }
        long endTime=System.nanoTime();
        System.gc();
        return  (endTime-startTime)/1000000000.0;
    }
}
